<?php
function showTable ($n3, $n2, $n1)
{
    $tempStr = "<td style=\"border-left-width:4px;\">" . $n3 . "</td>\r\n    <td>" . $n2 . "</td>\r\n    <td style=\"border-right-width:4px;\">" . $n1 . "</td>                                \r\n";
    return $tempStr;
}

function showTable_5 ($n5, $n4, $n3, $n2, $n1)
{
    $tempStr = "<td style=\"border-left-width:4px;\">{$n5}</td><td>{$n4}</td><td>{$n3}</td><td>{$n2}</td><td style=\"border-right-width:4px;\">{$n1}</td>";
    return $tempStr;
}

function showTable_two_5 ($n10, $n9, $n8, $n7, $n6, $n5, $n4, $n3, $n2, $n1)
{
    $tempStr = "<td style=\"border-left-width:4px;\">{$n10}</td><td>{$n9}</td><td>{$n8}</td><td>{$n7}</td><td>{$n6}</td>\r\n            <td>{$n5}</td><td>{$n4}</td><td>{$n3}</td><td>{$n2}</td><td>{$n1}</td>";
    return $tempStr;
}

function big_samll ($a, $b, $c)
{
    $result = max($a, $b, $c) - min($a, $b, $c);
    $tempStr = "<td nowrap align=center>{$result}</td>";
    return $tempStr;
}

function showTableTwo ($n3, $n2, $n1)
{
    $tempStr = "<td>" . $n3 . "</td>\r\n    <td>" . $n2 . "</td>\r\n    <td style=\"border-right-width:4px;\">" . $n1 . "</td>";
    return $tempStr;
}

if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval(getvar("gametype"));
$chk = new CheckMode_3d($curruser['acl'], 3, $gametype);
$chk->checkShow3dPage();
$show3D3S = $chk->show3D3S;
$getShow35 = getShow35($gametype);
unset($chk);
$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
require_once( "class_3d/MyLotto_3d.php" );
require_once( "class_3d/class.lotto3d.php" );
$MyLotto_3d = new MyLotto_3d($gametype);
$lotto3d=new lotto3d($gametype);
$ui = new UI_3D(true);
$tpl = new Template2();
$page = getvar("page");
$page = $page == "" ? 1 : intval($page);
$ymdhis = date("Y-m-d H:i:s");
switch ($show3D3S)
{
    case 0 :
        $rs = $MyLotto_3d->getDataList($page, 10);
        $showOpenTime = false;
        break;
    case 1 :
        $rs = $MyLotto_3d->getDataList3s($page, 10, $show3D3S);
        $showOpenTime = true;
        break;
}
if ($rs->eof)
{
    $list = "<tr><td colspan=40>目前无{$tblName}相关资料</td></tr>";
}
else if ($getShow35)
{
    $list = "<tbody id=\"tbdList\">";
    while (!$rs->eof)
    {
        $n5 = $rs->f['n5'] == 0 - 1 ? "" : $rs->f['n5'];
        $n4 = $rs->f['n4'] == 0 - 1 ? "" : $rs->f['n4'];
        $n3 = $rs->f['n3'] == 0 - 1 ? "" : $rs->f['n3'];
        $n2 = $rs->f['n2'] == 0 - 1 ? "" : $rs->f['n2'];
        $n1 = $rs->f['n1'] == 0 - 1 ? "" : $rs->f['n1'];
        $openFlag = $MyLotto_3d->checkOpen($rs->f['n3'], $rs->f['n2'], $rs->f['n1'], $rs->f['n4'], $rs->f['n5']);
        if ($showOpenTime)
        {
            $classStr = $ymdhis <= $rs->f['openbet'] && $rs->f['startbet'] <= $ymdhis ? "td6" : "td2";
        }
        else
        {
            $classStr = $rs->f['open'] == date("Y-m-d") ? "td6" : "td2";
        }
        $list .= "<tr class=\"" . $classStr . "\" align=\"center\">";
        $dateNum = date("w", strtotime($rs->f['open']));
        $list .= "<td nowrap>" . $rs->f['round'] . "</td>";
        $list .= "<td style=\"border-left-width:4px;\" nowrap>" . $g_weekname[$dateNum] . "</td>";
        $list .= "<td style=\"border-left-width:4px; border-right-width:4px;\" nowrap>" . $rs->f['open'] . "</td>";
        if ($showOpenTime)
        {
            $openbetIntTemp = strtotime($rs->f['openbet']);
            if (date("Y-m-d", $openbetIntTemp) != $rs->f['open'])
            {
                $list .= "<td nowrap class=\"td14\">";
            }
            else
            {
                $list .= "<td nowrap>";
            }
            $list .= date("H:i", $openbetIntTemp) . "</td>";
        }
        if ($openFlag)
        {
            $total = $n5 + $n4 + $n3 + $n2 + $n1;
            if ($total == 0 || $total % 2 == 0)
            {
                $total_sd = 2;
            }
            else
            {
                $total_sd = 1;
            }
            if (22 < $total)
            {
                $total_bs = 1;
            }
            else
            {
                $total_bs = 2;
            }
            $animal = 3;
            if ($n1 < $n5)
                $animal = 1;
			elseif ($n1 > $n5)
				$animal = 2;
            else
                $animal = 3;
            $list .= "<td style=\"border-left-width:4px;\" nowrap class=\"ball3dBg\">" . $n5 . "</td>";
            $list .= "<td nowrap class=\"ball3dBg\">" . $n4 . "</td>";
            $list .= "<td nowrap class=\"ball3dBg\">" . $n3 . "</td>";
            $list .= "<td nowrap class=\"ball3dBg\">" . $n2 . "</td>";
            $list .= "<td nowrap style=\"border-right-width:4px;\" class=\"ball3dBg\">" . $n1 . "</td>";
            $list .= showTableTwo($MyLotto_3d->showText($total_bs, "bs"), $MyLotto_3d->showText($total_sd, "sd"), $MyLotto_3d->showText($animal, "animal"));
            //$list .= big_samll($n5, $n4, $n3);
            //$list .= big_samll($n4, $n3, $n2);
            //$list .= big_samll($n3, $n2, $n1);
            $list .= showTable_5($MyLotto_3d->showText($rs->f['p5sd'], "sd"), $MyLotto_3d->showText($rs->f['p4sd'], "sd"), $MyLotto_3d->showText($rs->f['p3sd'], "sd"), $MyLotto_3d->showText($rs->f['p2sd'], "sd"), $MyLotto_3d->showText($rs->f['p1sd'], "sd"));
            $list .= showTable_5($MyLotto_3d->showText($rs->f['p5bs'], "bs"), $MyLotto_3d->showText($rs->f['p4bs'], "bs"), $MyLotto_3d->showText($rs->f['p3bs'], "bs"), $MyLotto_3d->showText($rs->f['p2bs'], "bs"), $MyLotto_3d->showText($rs->f['p1bs'], "bs"));
            $list .= showTable_5($MyLotto_3d->showText($rs->f['p5pc'], "pc"), $MyLotto_3d->showText($rs->f['p4pc'], "pc"), $MyLotto_3d->showText($rs->f['p3pc'], "pc"), $MyLotto_3d->showText($rs->f['p2pc'], "pc"), $MyLotto_3d->showText($rs->f['p1pc'], "pc"));
            $list .= "<td>".$MyLotto_3d->showText($lotto3d->GetOther($rs->f['n3'],$rs->f['n4'],$rs->f['n5']),'other')."</td>";
			$list .= "<td>".$MyLotto_3d->showText($lotto3d->GetOther($rs->f['n2'],$rs->f['n3'],$rs->f['n4']),'other')."</td>";
			$list .= "<td>".$MyLotto_3d->showText($lotto3d->GetOther($rs->f['n1'],$rs->f['n2'],$rs->f['n3']),'other')."</td>";
			$list .= "<td>".$MyLotto_3d->showText($rs->f['nn'], "nn")."</td>";
			$list .= "<td>".$MyLotto_3d->showText($rs->f['sh'], "sh")."</td>";
			//$list .= showTable_two_5($MyLotto_3d->showText($rs->f['r2a_p54sd'], "sd"), $MyLotto_3d->showText($rs->f['r2a_p53sd'], "sd"), $MyLotto_3d->showText($rs->f['r2a_p52sd'], "sd"), $MyLotto_3d->showText($rs->f['r2a_p51sd'], "sd"), $MyLotto_3d->showText($rs->f['r2a_p43sd'], "sd"), $MyLotto_3d->showText($rs->f['r2a_p42sd'], "sd"), $MyLotto_3d->showText($rs->f['r2a_p41sd'], "sd"), $MyLotto_3d->showText($rs->f['r2p0sd'], "sd"), $MyLotto_3d->showText($rs->f['r2p1sd'], "sd"), $MyLotto_3d->showText($rs->f['r2p2sd'], "sd"));
        }
        else
        {
            $list .= "<td style=\"border-left-width:4px;\" colspan=\"34\">&nbsp;</td>";
        }
        $list .= "</tr>";
        $rs->movenext();
    }
    $list .= "</tbody>";
}
else
{
    $list = "<tbody id=\"tbdList\">";
    while (!$rs->eof)
    {
        $n3 = $rs->f['n3'] == 0 - 1 ? "" : $rs->f['n3'];
        $n2 = $rs->f['n2'] == 0 - 1 ? "" : $rs->f['n2'];
        $n1 = $rs->f['n1'] == 0 - 1 ? "" : $rs->f['n1'];
        $openFlag = $MyLotto_3d->checkOpen($rs->f['n3'], $rs->f['n2'], $rs->f['n1']);
        if ($showOpenTime)
        {
            $classStr = $ymdhis <= $rs->f['openbet'] && $rs->f['startbet'] <= $ymdhis ? "td6" : "td2";
        }
        else
        {
            $classStr = $rs->f['open'] == date("Y-m-d") ? "td6" : "td2";
        }
        $list .= "<tr class=\"" . $classStr . "\" align=\"center\">";
        $dateNum = date("w", strtotime($rs->f['open']));
        $list .= "<td nowrap>" . $rs->f['round'] . "</td>";
        $list .= "<td style=\"border-left-width:4px;\" nowrap>" . $g_weekname[$dateNum] . "</td>";
        $list .= "<td style=\"border-left-width:4px; border-right-width:4px;\" nowrap>" . $rs->f['open'] . "</td>";
        if ($showOpenTime)
        {
            $openbetIntTemp = strtotime($rs->f['openbet']);
            if (date("Y-m-d", $openbetIntTemp) != $rs->f['open'])
            {
                $list .= "<td nowrap class=\"td14\">";
            }
            else
            {
                $list .= "<td nowrap>";
            }
            $list .= date("H:i", $openbetIntTemp) . "</td>";
        }
        if ($openFlag)
        {
            $list .= "<td style=\"border-left-width:4px;\" nowrap class=\"ball3dBg\">" . $n3 . "</td>";
            $list .= "<td nowrap class=\"ball3dBg\">" . $n2 . "</td>";
            $list .= "<td style=\"border-right-width:4px;\" nowrap class=\"ball3dBg\">" . $n1 . "</td>";
            $list .= big_samll($n3, $n2, $n1);
            $list .= showTable($MyLotto_3d->showText($rs->f['p3sd'], "sd"), $MyLotto_3d->showText($rs->f['p2sd'], "sd"), $MyLotto_3d->showText($rs->f['p1sd'], "sd"));
            $list .= showTable($MyLotto_3d->showText($rs->f['p3bs'], "bs"), $MyLotto_3d->showText($rs->f['p2bs'], "bs"), $MyLotto_3d->showText($rs->f['p1bs'], "bs"));
            $list .= showTable($MyLotto_3d->showText($rs->f['p3pc'], "pc"), $MyLotto_3d->showText($rs->f['p2pc'], "pc"), $MyLotto_3d->showText($rs->f['p1pc'], "pc"));
            $list .= showTableTwo($MyLotto_3d->showText($rs->f['r2p0sd'], "sd"), $MyLotto_3d->showText($rs->f['r2p1sd'], "sd"), $MyLotto_3d->showText($rs->f['r2p2sd'], "sd"));
            $list .= "<td style=\"border-right-width:4px;\" nowrap align=center>" . $MyLotto_3d->showText($rs->f['p321sd'], "sd") . "</td>";
            $list .= "<td nowrap align=center>" . $MyLotto_3d->showText($rs->f['p321bs'], "bs") . "</td>";
        }
        else
        {
            $list .= "<td style=\"border-left-width:4px;\" colspan=\"19\">&nbsp;</td>";
        }
        $list .= "</tr>";
        $rs->movenext();
    }
    $list .= "</tbody>";
}
$getOpenUrl = $MyLotto_3d->getOpenUrl($gametype);
$btnLink = $getOpenUrl != "" ? "<input type='button' value='官网' class='colorBtn01 clrBrd_{$gametype}' onclick=\"javascript:window.open('{$getOpenUrl}', '_blank')\" />" : "";
$tpl3_5 = $getShow35 ? "result_5.htm" : "result.htm";
//$tpl->load("main", "{$tpl3_5}");
$tpl->load( array("menu" => ($gametype==24?'pk':'ssc')."_menu.htm","main" => $tpl3_5) );
$tpl->set("gametype",$gametype);
$tpl->show( "menu" );
$tpl->set(array("list" => $list, "button" => $rs->pagelink(), "gametypeStr" => $tblName, "gametype" => "bgClc_{$gametype}", "title_gametype" => " bgImg_{$gametype}", "btnLink" => $btnLink));
if ($showOpenTime)
{
    $tpl->set(array("showOpenTimeTd" => "<td width=\"1%\" style=\"border-bottom-width=4px;\" rowspan=\"2\">开奖<br />时间</td>", "showOpenTimeTd02" => "<td>&nbsp;</td>", "note3s" => "<div>※开奖时间背景颜色为<span class=\"td14\">粉红色</span>时，代表已过凌晨(开奖日期 = 报表日期加一天)</div>"));
}
$jslink = "<script src=\"core/tpl/k2/jquery-1.4.2.min.js\"></script>\n";
$ui->set("jslink", $jslink);
$ui->set("csscode", ".ball3dBg{font-size:20px;} table td{font-size:16px;}");
$ui->header();
$ui->showNews3D($curruser['acl'],1);
$getOpenUrl = $MyLotto_3d->getOpenUrl($gametype);
echo "<br />";
$tpl->show("main");
$ui->footer();
?>